var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/Radio/RadioWithOther/index.tsx
var RadioWithOther_exports = {};
__export(RadioWithOther_exports, {
  default: () => RadioWithOther_default
});
module.exports = __toCommonJS(RadioWithOther_exports);
var import_antd = require("antd");
var import_style = require("antd/es/radio/style/index.js");
var import_classnames = __toESM(require("classnames"));
var import_react = __toESM(require("react"));
var import_createField = __toESM(require("../../createField"));
var import_FieldContext = require("../../_utils/contexts/FieldContext");
var import_useOther = __toESM(require("../../_utils/hooks/useOther"));
var import_useRequestOptions = __toESM(require("../../_utils/hooks/useRequestOptions"));
var import_index = require("./index.less");
var RadioWithOther = (0, import_react.forwardRef)(
  ({ value, onChange, options: optionsOrRequest, className, ...rest }, ref) => {
    const { label } = (0, import_FieldContext.useFieldContext)();
    const { options } = (0, import_useRequestOptions.default)(optionsOrRequest);
    const otherRef = (0, import_react.useRef)("radio-other-" + Math.random());
    const {
      otherChecked,
      changeOtherChecked,
      selectedValue,
      changeSelectedValue,
      otherValue,
      changeOtherValue
    } = (0, import_useOther.default)({
      mode: "single",
      value,
      onChange,
      options
    });
    const handleRadioChange = (0, import_react.useCallback)(
      (val) => {
        const found = options.find((option) => option.value === val);
        if (found) {
          changeOtherChecked(false);
          changeSelectedValue(found.value);
        } else {
          changeOtherChecked(true);
        }
      },
      [options, changeSelectedValue, changeOtherChecked]
    );
    const handleInputChange = (0, import_react.useCallback)(
      (event) => {
        changeOtherValue(event.target.value);
      },
      [changeOtherValue]
    );
    return /* @__PURE__ */ import_react.default.createElement("span", { className: (0, import_classnames.default)("szzj-radio-with-other", className) }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Radio.Group,
      {
        value: otherChecked ? otherRef.current : selectedValue == null ? void 0 : selectedValue[0],
        onChange: (event) => {
          handleRadioChange(event.target.value);
        },
        ...rest,
        className: "szzj-radio-with-other-radio",
        options: [
          ...options,
          {
            value: otherRef.current,
            label: /* @__PURE__ */ import_react.default.createElement(import_react.Fragment, null, "其他", otherChecked && /* @__PURE__ */ import_react.default.createElement(
              import_antd.Input,
              {
                placeholder: `请输入${label || ""}`,
                maxLength: 100,
                className: "szzj-radio-with-other-input",
                value: otherValue,
                onChange: handleInputChange
              }
            ))
          }
        ],
        ref
      }
    ));
  }
);
var RadioWithOther_default = (0, import_createField.default)(
  RadioWithOther
);
